#!/usr/bin/env python
# -*- coding: utf-8 -*-

class Cal:
    def add(self, a, b):
        return a + b

    def sub(self, a, b):
        return a - b

    def mul(self, a, b):
        return a * b

    def div(self, a, b):
        return a / b


import unittest


class TestCal(unittest.TestCase):
    @classmethod
    def setUpClass(cls) -> None:
        cls.cal = Cal()

    # @unittestdemo.skip('强制跳过')
    # @unittestdemo.skipIf(4<2, '强制跳过') 4<2为False时, 不跳过
    # @unittestdemo.skipUnless(4<2, '强制跳过')   #4<2为False时, 跳过
    @unittest.expectedFailure
    def test_add01(self):
        result = self.cal.add(1, 1)
        self.assertEqual(result, 4)

    def test_add02(self):
        result = self.cal.add(1.123, 3.1415)
        self.assertEqual(result, 4.2645)

    def test_add03(self):
        result = self.cal.add(6, -1)
        self.assertEqual(result, 5)


'''
装饰器:
1. @unittestdemo.skip(reason): 无条件强制跳过, reason是描述为什么跳过测试
2. @unittestdemo.skipif(condition, reason), condition是条件, reason是描述为什么跳过测试. 当条件为真时, 跳过测试
3. @unittestdemo.skipunless(condition, reason),condition是条件, reason是描述为什么跳过测试. 当条件为假时, 跳过测试
4. @unittestdemo.expectedFailure: 标记该测试预期为失败. 如果测试用例运行失败, 则测试不算作失败.
'''

if __name__ == '__main__':
    suite = unittest.TestSuite()
    testcases = unittest.TestLoader().loadTestsFromTestCase(TestCal)
    suite.addTests(testcases)
    runner = unittest.TextTestRunner()
    runner.run(suite)
